package lagou.homework.lagouhomework.Unit3.code.q5;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Collections;

public class Card {
    private static String[] cardNum = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2", "小王", "大王"};
    private static String[] color = { "黑桃", "红桃", "梅花", "方块" };
    private static Map<Integer, String> cards = new HashMap<>();
    private static List<Integer> orders = new ArrayList<>();
    private static List<Integer> card1 = new ArrayList<>(); // 存放底牌
    private static List<Integer> p1 = new ArrayList<>();        // 存放玩家1的牌
    private static List<Integer> p2 = new ArrayList<>();        // 存放玩家2的牌
    private static List<Integer> p3 = new ArrayList<>();        // 存放玩家3的牌



    public static void initCard(){
        int index = 1;
        for(int i=0; i<cardNum.length-2; i++){
            for(int j =0;j<color.length;j++) {
                // System.out.println(cardNum[i]+"...."+color[j]+"..."+index);
                cards.put(index, cardNum[i]);
                orders.add(index);
                index ++;
            }
        }
        cards.put(index, "小王");
        orders.add(index);
        index ++;
        cards.put(index, "大王");
        orders.add(index);
    }

    public static void shuffleCard(){
        Collections.shuffle(orders);
    }

    public static void putCard(){
        for (int i = 0; i < orders.size(); i++) {
            int id = orders.get(i);
            if(i<3){
                card1.add(id);
            }
            else if (i%3==1) {
                p1.add(id);
            }else if(i%3==2){
                p2.add(id);
            }else{
                p3.add(id);
            }
        }
        // 对每个人的牌进行排序
        Collections.sort(card1);
        Collections.sort(p1);
        Collections.sort(p2);
        Collections.sort(p3);



    }


    //  打印牌
    private static void show1(List<Integer> p){
        for (Integer i : p) {

            System.out.print(cards.get(i)+" ");
        }
        System.out.println("");

    }

    // 展示每个人的牌及底牌
    public static void showCards(){
        System.out.println("底牌：" );
        show1(card1);
        System.out.println("玩家1：" );
        show1(p1);
        System.out.println("玩家2：" );
        show1(p2);
        System.out.println("玩家3：" );
        show1(p3);

    }



}
